package com.example.e;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.e.Adapter.CatograyAdapter;
import com.example.e.Adapter.GoodsAdapter;
import com.example.e.Adapter.GoodsDetailAdapter;
import com.example.e.Adapter.ProductAdapter;
import com.example.e.Bean.CatograyBean;
import com.example.e.Bean.GoodsBean;
import com.example.e.Bean.ItemBean;
import com.example.e.View.MyListView;
import com.flipboard.bottomsheet.BottomSheetLayout;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class FoodActivity extends Activity {
    //控件
    private ListView lv_catogary, lv_good;
    private ImageView iv_logo;
    private TextView tv_car;
    private  TextView tv_count,tv_totle_money,tv_gocount;
    Double totleMoney = 0.00;
    private TextView bv_unm;
    private RelativeLayout rl_bottom;
    //分类和商品
    private List<CatograyBean> list = new ArrayList<CatograyBean>();
    private List<GoodsBean> list2 = new ArrayList<GoodsBean>();
    private MyApp myApp;
    private CatograyAdapter catograyAdapter;//分类的adapter
    private GoodsAdapter goodsAdapter;//分类下商品adapter
    ProductAdapter productAdapter;//底部购物车的adapter
    GoodsDetailAdapter goodsDetailAdapter;//套餐详情的adapter
    private static DecimalFormat df;
    private LinearLayout ll_shopcar;
    //底部数据
    private BottomSheetLayout bottomSheetLayout;
    private View bottomSheet;
    private SparseArray<GoodsBean> selectedList;
    //套餐
    private View bottomDetailSheet;
    private List<GoodsBean> list3 = new ArrayList<GoodsBean>();
    private List<GoodsBean> list4 = new ArrayList<GoodsBean>();
    private List<GoodsBean> list5 = new ArrayList<GoodsBean>();

    private Handler mHanlder;
    private ViewGroup anim_mask_layout;//动画层
    List<GoodsBean> submit_list = new ArrayList<>();
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food);
        myApp = (MyApp) getApplicationContext();
        mHanlder = new Handler(getMainLooper());
        initView();
        initData();
        addListener();
        selectedList.clear();
        ll_shopcar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showBottomSheet();
            }
        });
        tv_gocount = (TextView) findViewById(R.id.tv_gocount);
        tv_gocount.setOnClickListener(new View.OnClickListener() {

                @Override
            public void onClick(View v) {
                if(selectedList != null && selectedList.size()>0){
                    for(int i = 0; i < selectedList.size(); i++){
                        GoodsBean shopping = selectedList.valueAt(i);
                        submit_list.add(shopping);
                    }
                }
                Intent intent = new Intent(FoodActivity.this, SubmitActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("submit_list", (Serializable) submit_list);
                //bundle.putDouble("totleMoney",totleMoney);
                intent.putExtras(bundle);
                //Toast.makeText(FoodActivity.this,totleMoney.toString(),Toast.LENGTH_LONG).show();
                startActivity(intent);
                //selectedList.clear();

            }
        });
    }

    public void initView() {
        lv_catogary = (ListView) findViewById(R.id.lv_catogary);
        lv_good = (ListView) findViewById(R.id.lv_good);
        tv_car = (TextView) findViewById(R.id.tv_car);
        //底部控件
        rl_bottom = (RelativeLayout) findViewById(R.id.rl_bottom);
        tv_count = (TextView) findViewById(R.id.tv_count);
        bv_unm = (TextView) findViewById(R.id.bv_unm);
        tv_totle_money= (TextView) findViewById(R.id.tv_totle_money);
        ll_shopcar= (LinearLayout) findViewById(R.id.ll_shopcar);
        selectedList = new SparseArray<>();
        df = new DecimalFormat("0.00");
    }

    //填充数据
    private void initData() {
        //商品
        for (int j=30;j<31;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("人气单人餐");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.hanyouwang.com%2Fstore%2F20180108%2F1515401869119423.png&refer=http%3A%2F%2Fimg.hanyouwang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612507903&t=5830231f3cbe213dc818cdf5025a5060");
            goodsBean.setOriginal_price("28");
            goodsBean.setPrice("23.9");
            list3.add(goodsBean);
        }
        for (int j=31;j<32;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("中翅套餐");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1279918189,608483102&fm=26&gp=0.jpg");
            goodsBean.setOriginal_price("22");
            goodsBean.setPrice("19.9");
            list3.add(goodsBean);
        }
        for (int j=32;j<33;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("无骨鸡套餐");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp1.meituan.net%2Fdeal%2F3806836a9c53269ab2fa651b7e7204ef52137.jpg%2540700w_700h_1e_1c_1l%257Cwatermark%3D1%26%26r%3D1%26p%3D9%26x%3D2%26y%3D2%26relative%3D1%26o%3D20&refer=http%3A%2F%2Fp1.meituan.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612513445&t=7dc61422cbc9e5ef0a915812e78faceb");
            goodsBean.setOriginal_price("25");
            goodsBean.setPrice("17.9");
            list3.add(goodsBean);
        }
        for (int j=33;j<34;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("半只鸡套餐");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcp2.douguo.net%2Fupload%2Fcaiku%2Ff%2F7%2F8%2Fyuan_f7b3bdf72aaa8dfbccc681788781bff8.jpg&refer=http%3A%2F%2Fcp2.douguo.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612511949&t=635a8ac6e2bd7945c517b3b6da71209a");
            goodsBean.setOriginal_price("30");
            goodsBean.setPrice("27.9");
            list3.add(goodsBean);
        }
        for (int j=34;j<35;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("整只鸡+年糕");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqcloud.dpfile.com%2Fpc%2FXLOlvXTFLNtCdVB3qmlVc9rRiwkRhMoaIxU_ZrSdmUbUiURwWfT9vPdxmK5NZTF8TYGVDmosZWTLal1WbWRW3A.jpg&refer=http%3A%2F%2Fqcloud.dpfile.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612512139&t=36c7f9d4572ea3f567fb8eeee8f41fdf");
            goodsBean.setOriginal_price("40");
            goodsBean.setPrice("33.9");
            list3.add(goodsBean);
        }
        for (int j=35;j<36;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("爆款甜辣炸鸡");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.alicdn.com%2Fi1%2F1830412448%2FTB2LznBxeuSBuNjSsziXXbq8pXa_%21%211830412448.jpg&refer=http%3A%2F%2Fimg.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612512425&t=b286d226533874cb5dd544fa077635a5");
            goodsBean.setOriginal_price("30");
            goodsBean.setPrice("27.9");
            list3.add(goodsBean);
        }
        for (int j=36;j<37;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("奶香芝士炸鸡");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20180617%2F1387aaf5498e4ee59dc9ae9c8c569c2c.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612512642&t=1b2c7333aeba8c56bff3a34c04f376d2");
            goodsBean.setOriginal_price("30");
            goodsBean.setPrice("27.9");
            list3.add(goodsBean);
        }
        for (int j=37;j<38;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("琥珀甜辣炸鸡");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcbu01.alicdn.com%2Fimg%2Fibank%2F2016%2F286%2F555%2F2996555682_624658085.jpg&refer=http%3A%2F%2Fcbu01.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612512797&t=94c6e157012ca9b86687425004f0e644");
            goodsBean.setOriginal_price("30");
            goodsBean.setPrice("27.9");
            list3.add(goodsBean);
        }
        for (int j=38;j<39;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("酸甜炸鸡");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqcloud.dpfile.com%2Fpc%2FpmtCQy0OhYN6TD21UQ3ifgIy5Dwo4nx0IJ8Z4M_nWHVWAmLthtxsKw2710jOUP3RTK-l1dfmC-sNXFHV2eRvcw.jpg&refer=http%3A%2F%2Fqcloud.dpfile.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612512894&t=918a28fb10469081c06ae9fff75dcb7d");
            goodsBean.setOriginal_price("30");
            goodsBean.setPrice("27.9");
            list3.add(goodsBean);
        }
        for (int j=39;j<40;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("蜂蜜芥末炸鸡");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201901%2F20%2F20190120170453_cmGxk.thumb.700_0.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612508073&t=1768d94972252313d95fc3206c7a7e26");
            goodsBean.setOriginal_price("30");
            goodsBean.setPrice("27.9");
            list3.add(goodsBean);
        }
        for (int j=40;j<41;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("韩式双拼大份炸鸡");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqcloud.dpfile.com%2Fpc%2FqivJ7W3M6BZoSK_KTFSzLVtILsqx1h9JKKXhG17JVnZ2Z2NWo8mGzuxwarQuIULZTYGVDmosZWTLal1WbWRW3A.jpg&refer=http%3A%2F%2Fqcloud.dpfile.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612508073&t=f930b855d9a5c86de557e8a2040e8a07");
            goodsBean.setOriginal_price("40");
            goodsBean.setPrice("38.9");
            list3.add(goodsBean);
        }

        //商品
        for (int j=5;j<6;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("薯条");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimage.f600.cn%2FJMSpider%2Fdd39c3d58e42476bb338aaa92e80e80c%2F158E2A38B5F.jpg&refer=http%3A%2F%2Fimage.f600.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612511855&t=ffa15662c5e8b4ae876af19589efc9c0");
            goodsBean.setOriginal_price("10");
            goodsBean.setPrice("7.9");
            list4.add(goodsBean);
        }
        for (int j=6;j<7;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("黑椒鸡块");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg4.tbcdn.cn%2Ftfscom%2Fi2%2F86789891%2FTB2VVlrlVXXXXXnXXXXXXXXXXXX_%21%2186789891.jpg&refer=http%3A%2F%2Fimg4.tbcdn.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612513297&t=ee3e5c2c219334c5a723a5dc6a2c1095");
            goodsBean.setOriginal_price("10");
            goodsBean.setPrice("8.88");
            list4.add(goodsBean);
        }
        for (int j=31;j<32;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("芝士年糕");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=477851270,1416205473&fm=26&gp=0.jpg");
            goodsBean.setOriginal_price("20");
            goodsBean.setPrice("9.9");
            list4.add(goodsBean);
        }

        //商品
        for (int j=10;j<11;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("珍珠奶茶");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fphoto.16pic.com%2F00%2F13%2F54%2F16pic_1354066_b.jpg&refer=http%3A%2F%2Fphoto.16pic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612513704&t=f86b4ad71c8ce95174a58fdd3909a8f4");
            goodsBean.setOriginal_price("20");
            goodsBean.setPrice("15");
            list5.add(goodsBean);
        }
        for (int j=11;j<12;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("红豆奶茶");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1592903485,3883393154&fm=26&gp=0.jpg");
            goodsBean.setOriginal_price("20");
            goodsBean.setPrice("15");
            list5.add(goodsBean);
        }
        for (int j=12;j<13;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("可乐");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcuimg.zuyushop.com%2Fcuxiaopic%2Fimage%2Fmmbadmin%2F20160518134622_1213.jpg&refer=http%3A%2F%2Fcuimg.zuyushop.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612514043&t=07dd4ad271ff2ba4dfeb0cb75b97d379");
            goodsBean.setOriginal_price("20");
            goodsBean.setPrice("15");
            list5.add(goodsBean);
        }
        for (int j=13;j<14;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("芬达");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fm.ntcai.com%2Fimages%2F201803%2Fgoods_img%2F2970_P_1522196422877.jpg&refer=http%3A%2F%2Fm.ntcai.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612514117&t=af4de478dbfb38e5cebd5783416133b8");
            goodsBean.setOriginal_price("5");
            goodsBean.setPrice("3.99");
            list5.add(goodsBean);
        }
        for (int j=14;j<15;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("李子园");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1419916635,2750861983&fm=26&gp=0.jpg");
            goodsBean.setOriginal_price("8");
            goodsBean.setPrice("4.99");
            list5.add(goodsBean);
        }
        for (int j=15;j<16;j++){
            GoodsBean goodsBean = new GoodsBean();
            goodsBean.setTitle("橙汁");
            goodsBean.setProduct_id(j);
            goodsBean.setCategory_id(j);
            goodsBean.setIcon("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fbpic.588ku.com%2Felement_origin_min_pic%2F17%2F05%2F26%2F09a2a5b4d1f9593919bb8c7603d4518a.jpg&refer=http%3A%2F%2Fbpic.588ku.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1612514437&t=ba7f4327f8edbf40ce4dcc7b057ea059");
            goodsBean.setOriginal_price("20");
            goodsBean.setPrice("15");
            list5.add(goodsBean);
        }

        CatograyBean catograyBean3 = new CatograyBean();
        catograyBean3.setCount(3);
        catograyBean3.setKind("炸鸡套餐");
        catograyBean3.setList(list3);
        list.add(catograyBean3);

        CatograyBean catograyBean4 = new CatograyBean();
        catograyBean4.setCount(4);
        catograyBean4.setKind("美味小食");
        catograyBean4.setList(list4);
        list.add(catograyBean4);

        CatograyBean catograyBean5 = new CatograyBean();
        catograyBean5.setCount(5);
        catograyBean5.setKind("冬日饮品");
        catograyBean5.setList(list5);
        list.add(catograyBean5);
        bottomSheetLayout = (BottomSheetLayout) findViewById(R.id.bottomSheetLayout);

        //默认值
        list2.clear();
        list2.addAll(list.get(0).getList());

        //分类
        catograyAdapter = new CatograyAdapter(this, list);
        lv_catogary.setAdapter(catograyAdapter);
        catograyAdapter.notifyDataSetChanged();
        //商品
        goodsAdapter = new GoodsAdapter(this, list2, catograyAdapter);
        lv_good.setAdapter(goodsAdapter);
        goodsAdapter.notifyDataSetChanged();

    }


    //添加监听
    private void addListener() {
        lv_catogary.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.i("fyg","list.get(position).getList():"+list.get(position).getList());
                list2.clear();
                list2.addAll(list.get(position).getList());
                catograyAdapter.setSelection(position);
                catograyAdapter.notifyDataSetChanged();
                goodsAdapter.notifyDataSetChanged();


            }
        });
    }





    //创建套餐详情view
    public void showDetailSheet(List<ItemBean> listItem, String mealName){
        bottomDetailSheet = createMealDetailView(listItem,mealName);
        if(bottomSheetLayout.isSheetShowing()){
            bottomSheetLayout.dismissSheet();
        }else {
            if(listItem.size()!=0){
                bottomSheetLayout.showWithSheetView(bottomDetailSheet);
            }
        }
    }

    //查看套餐详情
    private View createMealDetailView(List<ItemBean> listItem, String mealName){
        View view = LayoutInflater.from(this).inflate(R.layout.activity_goods_detail,(ViewGroup) getWindow().getDecorView(),false);
        ListView lv_product = (com.example.e.View.MyListView) view.findViewById(R.id.lv_product);
        TextView tv_meal = (TextView) view.findViewById(R.id.tv_meal);
        TextView tv_num = (TextView) view.findViewById(R.id.tv_num);
        int count=0;
        for(int i=0;i<listItem.size();i++){
            count = count+Integer.parseInt(listItem.get(i).getNote2());
        }
        tv_meal.setText(mealName);
        tv_num.setText("(共"+count+"件)");
        goodsDetailAdapter = new GoodsDetailAdapter(FoodActivity.this,listItem);
        lv_product.setAdapter(goodsDetailAdapter);
        goodsDetailAdapter.notifyDataSetChanged();
        return view;
    }


    //创建购物车view
    private void showBottomSheet(){
        bottomSheet = createBottomSheetView();
        if(bottomSheetLayout.isSheetShowing()){
            bottomSheetLayout.dismissSheet();
        }else {
            if(selectedList.size()!=0){
                bottomSheetLayout.showWithSheetView(bottomSheet);
            }
        }
    }


    //查看购物车布局
    private View createBottomSheetView(){
        View view = LayoutInflater.from(this).inflate(R.layout.layout_bottom_sheet,(ViewGroup) getWindow().getDecorView(),false);
        MyListView lv_product = (MyListView) view.findViewById(R.id.lv_product);
        TextView clear = (TextView) view.findViewById(R.id.clear);
        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clearCart();
            }
        });
        productAdapter = new ProductAdapter(FoodActivity.this,goodsAdapter, selectedList);
        lv_product.setAdapter(productAdapter);
        return view;
    }

    //清空购物车
    public void clearCart(){
        selectedList.clear();
        list2.clear();
        if (list.size() > 0) {
            for (int j=0;j<list.size();j++){
                list.get(j).setCount(0);
                for(int i=0;i<list.get(j).getList().size();i++){
                    list.get(j).getList().get(i).setNum(0);
                }
            }
            list2.addAll(list.get(0).getList());
            catograyAdapter.setSelection(0);
            //刷新不能删
            catograyAdapter.notifyDataSetChanged();
            goodsAdapter.notifyDataSetChanged();
        }
        update(true);
    }


    //根据商品id获取当前商品的采购数量
    public int getSelectedItemCountById(int id){
        GoodsBean temp = selectedList.get(id);
        if(temp==null){
            return 0;
        }
        return temp.getNum();
    }


    public void handlerCarNum(int type, GoodsBean goodsBean, boolean refreshGoodList){
        if (type == 0) {
            GoodsBean temp = selectedList.get(goodsBean.getProduct_id());
            if(temp!=null){
                if(temp.getNum()<2){
                    goodsBean.setNum(0);
                    selectedList.remove(goodsBean.getProduct_id());

                }else{
                    int i =  goodsBean.getNum();
                    goodsBean.setNum(--i);
                }
            }



        } else if (type == 1) {
            GoodsBean temp = selectedList.get(goodsBean.getProduct_id());
            if(temp==null){
                goodsBean.setNum(1);
                selectedList.append(goodsBean.getProduct_id(), goodsBean);
            }else{
                int i= goodsBean.getNum();
                goodsBean.setNum(++i);
            }
        }

        update(refreshGoodList);

    }



    //刷新布局 总价、购买数量等
    private void update(boolean refreshGoodList){
        int size = selectedList.size();
        int count =0;
        for(int i=0;i<size;i++){
            GoodsBean item = selectedList.valueAt(i);
            count += item.getNum();
            totleMoney += item.getNum()*Double.parseDouble(item.getPrice());
        }
        tv_totle_money.setText("￥"+String.valueOf(df.format(totleMoney)));
        totleMoney = 0.00;
        if(count<1){
            bv_unm.setVisibility(View.GONE);
        }else{
            bv_unm.setVisibility(View.VISIBLE);
        }

        bv_unm.setText(String.valueOf(count));

        if(productAdapter!=null){
            productAdapter.notifyDataSetChanged();
        }

        if(goodsAdapter!=null){
            goodsAdapter.notifyDataSetChanged();
        }

        if(catograyAdapter!=null){
            catograyAdapter.notifyDataSetChanged();
        }

        if(bottomSheetLayout.isSheetShowing() && selectedList.size()<1){
            bottomSheetLayout.dismissSheet();
        }
    }


    /**
     * @Description: 创建动画层
     * @param
     * @return void
     * @throws
     */
    private ViewGroup createAnimLayout() {
        ViewGroup rootView = (ViewGroup) this.getWindow().getDecorView();
        LinearLayout animLayout = new LinearLayout(this);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        animLayout.setLayoutParams(lp);
        animLayout.setId(Integer.MAX_VALUE-1);
        animLayout.setBackgroundResource(android.R.color.transparent);
        rootView.addView(animLayout);
        return animLayout;
    }

    private View addViewToAnimLayout(final ViewGroup parent, final View view,
                                     int[] location) {
        int x = location[0];
        int y = location[1];
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.leftMargin = x;
        lp.topMargin = y;
        view.setLayoutParams(lp);
        return view;
    }

    public void setAnim(final View v, int[] startLocation) {
        anim_mask_layout = null;
        anim_mask_layout = createAnimLayout();
        anim_mask_layout.addView(v);//把动画小球添加到动画层
        final View view = addViewToAnimLayout(anim_mask_layout, v, startLocation);
        int[] endLocation = new int[2];// 存储动画结束位置的X、Y坐标
        tv_car.getLocationInWindow(endLocation);
        // 计算位移
        int endX = 0 - startLocation[0] + 40;// 动画位移的X坐标
        int endY = endLocation[1] - startLocation[1];// 动画位移的y坐标

        TranslateAnimation translateAnimationX = new TranslateAnimation(0,endX, 0, 0);
        translateAnimationX.setInterpolator(new LinearInterpolator());
        translateAnimationX.setRepeatCount(0);// 动画重复执行的次数
        translateAnimationX.setFillAfter(true);

        TranslateAnimation translateAnimationY = new TranslateAnimation(0, 0, 0, endY);
        translateAnimationY.setInterpolator(new AccelerateInterpolator());
        translateAnimationY.setRepeatCount(0);// 动画重复执行的次数
        translateAnimationY.setFillAfter(true);

        AnimationSet set = new AnimationSet(false);
        set.setFillAfter(false);
        set.addAnimation(translateAnimationY);
        set.addAnimation(translateAnimationX);
        set.setDuration(800);// 动画的执行时间
        view.startAnimation(set);
        // 动画监听事件
        set.setAnimationListener(new Animation.AnimationListener() {
            // 动画的开始
            @Override
            public void onAnimationStart(Animation animation) {
                v.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // TODO Auto-generated method stub
            }
            // 动画的结束
            @Override
            public void onAnimationEnd(Animation animation) {
                v.setVisibility(View.GONE);
            }
        });

    }


}
